package echat.future.cn.echat.my.view;

import android.app.Activity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Html;
import android.webkit.WebView;

import java.util.List;

import echat.future.cn.echat.R;
import echat.future.cn.echat.my.api.UserApi;
import echat.future.cn.echat.my.bean.UserProtocolBean;
import echat.future.cn.echat.my.utils.HttpUtilsRequst;
import echat.future.cn.echat.my.weight.Navagation.AdapterNavagation;
import echat.future.cn.echat.my.weight.Navagation.IBaseNavagation;
import lumingweihua.future.cn.baselibgxh.base.MyApplication;

public class UserProtocolActivity extends BaseActivity{

    WebView webView;


    @Override
    public int layoutId() {
        return R.layout.activity_user_protocol;
    }

    @Override
    public IBaseNavagation navagation() {
        return new AdapterNavagation(this).setTitle(this.getResources().getString(R.string.protocol),16,R.color.color_333333).setBack();
    }

    @Override
    public void initView() {
        webView = findViewById(R.id.webView);
        webView.getSettings().setJavaScriptEnabled(true);
        getUserAgree();
    }

    /**
     * 获取用户协议
     */
    private void getUserAgree(){
        new HttpUtilsRequst<List<String>>(this,
                HttpUtilsRequst.retrofitClient.create(UserApi.class)
                .getUserAgree()
                ).setmOnRequstSuccessListener((HttpUtilsRequst.OnRequstSuccessListener<List<UserProtocolBean>>) strings -> {

                    try {
                        setData(strings.get(0).getUseragree_con());
                    }catch (Exception e){
                        toast("加载用户协议出错");
                    }
                }).start();
    }


    private void setData(String content){
        webView.loadDataWithBaseURL(null, content, "text/html", "utf-8", null);
//        webView.loadData(content,"text/html", "utf-8");
    }
}
